package com.youlu.campus.service.share.impl;

import com.youlu.campus.base.exception.BusinessException;
import com.youlu.campus.entity.ActivityInfo;
import com.youlu.campus.entity.PointPlatformConfig;
import com.youlu.campus.entity.domain.QQMiniProgramShareDomain;
import com.youlu.campus.service.activity.ActivityService;
import com.youlu.campus.service.platform.PointPlatformConfigService;
import com.youlu.campus.service.share.QQMiniProgramShareService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.validation.constraints.NotNull;
import java.util.Objects;

@Slf4j
@Service
public class QQMiniProgramShareServiceImpl implements QQMiniProgramShareService {
    @Autowired
    private PointPlatformConfigService pointPlatformConfigService;
    @Autowired
    private ActivityService activityService;

    @Override
    public QQMiniProgramShareDomain getPlatformShareInfo(@NotNull String appId, String userId) {
        PointPlatformConfig config = pointPlatformConfigService.find(appId);
        if (Objects.isNull(config)) {
            log.error(":>>> QQ小程序积分平台配置不存在:{}", appId);
            throw new BusinessException("QQ小程序积分平台配置不存在");
        }
        QQMiniProgramShareDomain domain = new QQMiniProgramShareDomain();
        domain.setAppId(appId);
        domain.setPlatform("qq");
        domain.setShareTitle(config.getShareTitle());
        domain.setShareImageUrl(config.getShareImageUrl());
        domain.setUserId(userId);
        return domain;
    }

    @Override
    public QQMiniProgramShareDomain getActivityShareInfo(@NotNull String appId,
                                                         @NotNull String activityId,
                                                         @NotNull String userId) {

        ActivityInfo activityInfo = activityService.findOne(activityId);
        if (Objects.isNull(activityInfo)) {
            log.error(":>>> 活动不存在:{}", activityId);
            throw new BusinessException("活动不存在,请咨询客服!");
        }
        QQMiniProgramShareDomain domain = new QQMiniProgramShareDomain();
        domain.setAppId(appId);
        domain.setUserId(userId);
        domain.setPlatform("qq");
        domain.setShareImageUrl(activityInfo.getShareImageUrl());
        domain.setShareTitle(activityInfo.getShareName());
        domain.setActivityId(activityId);
        return domain;
    }


}
